package com.ftw.commons.utils

import com.ftw.commons.widgets.ZPopupWindow

/**
 * @Description:
 * @Author: fangtianwen
 * @Date: 2020/1/9 15:28
 */

object ZPopupWindowUtil {


    private var mDatas: ArrayList<ZPopupWindow> = ArrayList()

    fun getData(): ArrayList<ZPopupWindow> {
        return mDatas
    }

    fun setData(data: ArrayList<ZPopupWindow>) {
        mDatas = data
    }

    // 添加窗体
    @Synchronized
    fun addZPopupWindow(zPopupWindow: ZPopupWindow?) {
        if (zPopupWindow != null && !mDatas.contains(zPopupWindow)) mDatas.add(zPopupWindow)
    }

    // 移除窗体
    @Synchronized
    fun removeZPopupWindow(zPopupWindow: ZPopupWindow?) {
        if (zPopupWindow != null) {
            if (zPopupWindow.isShowing) zPopupWindow.dismiss()
            mDatas.remove(zPopupWindow)
        }
    }

    // 清空数据
    @Synchronized
    fun clearZPopupWindows() {
        for (zPopupWindow in mDatas) {
            zPopupWindow.dismiss()
        }
        mDatas.clear()
    }

    // 保留当前PopupWindow，移除其他所有
    @Synchronized
    fun clearZPopupWindowsKeepThis(zPopupWindow: ZPopupWindow) {
        for (i in 0 until mDatas.size) {
            val data = mDatas[i]
            if (data !== zPopupWindow && mDatas.contains(data)) {
                data.dismiss()
                mDatas.remove(data)
            }
        }
    }
}